<?php	
	session_start();
	include("/var/www/html/vivencias/conexaoBD.php");

	//Seleciona o grupo do usuario
	if($_SESSION['idTipoUsuario'] == "2"){
		$query     = "SELECT grupo FROM usuariosCursos WHERE idUsuario=".$_SESSION['idUsuario']." AND idCurso=".$_SESSION['idCurso'];
		$resultado = mysql_query($query,$conexao); 
		$objeto    = mysql_fetch_object($resultado);
	        $grupo     = $objeto->grupo;
	}else{
		$grupo = $_SESSION['salaReuniao']['grupoVisualizadoPeloProfessor'];
	}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Experi&ecirc;ncias do Processo de Adoecimento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="vivencias.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="F5FEFF">
<div align="center">
  <table width="550" border="0">
    <tr>
      <td align="center" valign="top"> <table width="95%" border="0" cellpadding="5" cellspacing="1">
          <tr> 
            <td align="center" valign="middle" bgcolor="d3f2f5"> <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                <tr align="center" bgcolor="#38708F" class="texttab"> 
                  <td width="93%" align="left" valign="top" bgcolor="9dd1d7"> 
                    <span class="ativo">F&oacute;rum grupo <?php echo $grupo;?></span></td>
                  <td width="7%" align="right" valign="top" bgcolor="9dd1d7"><div align="right"><a href="javascript:void(0);" onClick="javascript:var objWindow = window.open(location.href, '_self');objWindow.close();"><img src="imagens/x.jpg" width="21" height="21" border="0"></a></div></td>
                </tr>
                <tr align="center" bgcolor="#38708F" class="texttab"> 
                  <td colspan="2" align="left" valign="top" bgcolor="d3f2f5" class="texto2"><strong>Enviar 
                    coment&aacute;rio</strong></td>
                </tr>
		<form name="formForumSalaReuniao" action="insereMsgForumSalaReuniao.php" method="post">
                <tr align="center" bgcolor="#38708F" class="texttab"> 
                  <td colspan="2" align="left" valign="top" bgcolor="d3f2f5" class="texto2"><textarea name="comentario" cols="45" rows="5"></textarea> 
                  </td>
                </tr>
		<input type="hidden" name="grupo" value="<?php echo $grupo;?>">
                <tr align="center" bgcolor="#38708F" class="texttab">
                  <td colspan="2" align="left" valign="top" bgcolor="d3f2f5" class="texto2"><input type="submit" name="btEnviar" value="Enviar"> <!--<?php if(($_SESSION['idTipoUsuario'] == "0") || ($_SESSION['idTipoUsuario'] == "1")){ echo "disabled";}?>-->
                  </td>
                </tr>
		</form>
              </table></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><div align="center"> 
                <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                  <tr align="center" bgcolor="#38708F" class="texttab"> 
                    <!--<td align="left" valign="top" bgcolor="9dd1d7"> <span class="titsub">Usu&aacute;rios 
                      OnLine: Silvia Duarte / </span></td>-->
		      <form action="salaRForum.php" method="post">
		      <td align="left" valign="top" bgcolor="9dd1d7">
			<input type="submit" value="Atualizar Agora">
		      </td>
		      </form>
                  </tr>
                </table>
              </div></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><div align="center"> 
                <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                  <tr align="center" bgcolor="#38708F" class="texttab"> 
                    <td align="left" valign="top" bgcolor="9dd1d7"> <span class="titsub"><strong>Coment&aacute;rios</strong></span> 
                    </td>
                  </tr>
                </table>
              </div></td>
          </tr>
	  <?php
	    	$queryMsgs     = "SELECT salaReuniaoForum.mensagem,salaReuniaoForum.dataHora,usuarios.nome FROM salaReuniaoForum,usuarios WHERE salaReuniaoForum.idUsuario = usuarios.idUsuario AND salaReuniaoForum.idCurso=".$_SESSION['idCurso']." AND salaReuniaoForum.grupo=".$grupo." ORDER by salaReuniaoForum.dataHora DESC";
		$resultadoMsgs = mysql_query($queryMsgs,$conexao);
		while($objetoMsgs = mysql_fetch_object($resultadoMsgs)){ 
	  ?>
          <tr> 
            <td><table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                <tr align="center" bgcolor="#38708F" class="texttab"> 
                  <td align="left" valign="top" bgcolor="d3f2f5" class="texto">
		  	<?php 
				$comentario = $objetoMsgs->mensagem;
				$enter	    = array("\r\n", "\n", "\r");
                                $br	    = '<br />';
                            	$comentNovo = str_replace($enter, $br, $comentario);
				echo $comentNovo;

			?>
		  </td>
                </tr>
                <tr align="center" bgcolor="#38708F" class="texttab"> 
                  <td align="left" valign="top" bgcolor="bbe4e8"> 
		    <div align="left" class="texto2">
			<?php
				//Formatando a data-hora
				$dataHora = explode(" ",$objetoMsgs->dataHora);
				$data     = ereg_replace("([0-9]{2}([0-9]{2})?)[/.-]([01]?[0-9])[/.-]([0123]?[0-9])","\\4-\\3-\\1",$dataHora[0]);
				$hora     = $dataHora[1];

				echo $objetoMsgs->nome;
				echo " ".$data." ".$hora;
			?>
		    </div>
		  </td>
                </tr>
              </table>
              
            </td>
          </tr>
          <?php } ?>
         
          <tr> 
            <td>&nbsp; </td>
          </tr>
        </table>
        <p align="center">&nbsp;</p>
        <p><br>
        </p>
        </td>
    </tr>
  </table>
  <p>&nbsp;</p>
  </div>
</body>
</html>
